
package org.agilelang.editor.listener;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.File;
import javax.swing.JFileChooser;
import javax.swing.filechooser.FileFilter;
import org.agilelang.editor.ViewFrame;
import org.agilelang.editor.tool.InfoProject;

public class FileOpenProject implements ActionListener {

    ViewFrame frame;

    public FileOpenProject(ViewFrame frame) {
        this.frame = frame;
    }

    @Override
    public void actionPerformed(ActionEvent e) {
        //File current = new File(".");
        JFileChooser openFile = new JFileChooser(/*current*/);
        //openFile.setFileSelectionMode(JFileChooser.FILES_AND_DIRECTORIES);
        openFile.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
        openFile.addChoosableFileFilter(new FileFilter()//adds new filter into list
        {
            String description = "Project Agile";//the filter you see
            String extension = "project.pa";//the filter passed to program

            public String getDescription() {
                return description;
            }

            public boolean accept(File f) {
                if (f == null) {
                    return false;
                }
                if (f.isDirectory()) {
                    return true;
                }
                return f.getName().toLowerCase().endsWith(extension);
            }
        });
        if (openFile.showOpenDialog(null) == JFileChooser.APPROVE_OPTION) {
            System.out.println(openFile.getSelectedFile().getAbsolutePath());
            frame.setPathProject(openFile.getSelectedFile().getAbsolutePath());
            frame.openproject();
            /*InfoProject project = frame.getProject();
            project.open(openFile.getSelectedFile().getAbsolutePath());
            String app_path = openFile.getCurrentDirectory().getAbsolutePath();
            
            System.out.println(app_path);
            */
        }
    }
}
